package com.sl.au.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.MyMoney;
import com.sl.au.entity.MyMoneyType;
import com.sl.au.entity.User;
import com.sl.au.entity.myMoneyAll;
import com.sl.au.repository.MyMoneyRepository;
import com.sl.au.repository.MyMoneyTypeRepository;
import com.sl.au.service.MyMoneyAllService;

@Service("myMoneyAllService")
@Transactional
public class myMoneyAllServiceImpl extends BaseServiceImpl implements MyMoneyAllService{

	@Autowired
	MyMoneyRepository myMoneyRepository;
	
	@Autowired
	MyMoneyTypeRepository myMoneyTypeRepository;
	
	@Override
	public int saveMyMoneyAll(myMoneyAll mymoneyAll, User user) {
		String myMoneyId = null;
		String useContent = null;
		int code = 0;
		if(mymoneyAll.getApplyDept()!=null&&!mymoneyAll.getApplyDept().equals("")){
			MyMoney myMoney = new MyMoney();
			myMoney.setOutStartDate(mymoneyAll.getOutStartDate());
			myMoney.setBackDate(mymoneyAll.getBackDate());
			myMoney.setUseContent(mymoneyAll.getUseContent());
			myMoney.setOutDays(mymoneyAll.getOutDays());
			myMoney.setApplyUser(mymoneyAll.getApplyUser());//申请人id
			myMoney.setApplyUserName(mymoneyAll.getApplyUserName());//申请人姓名
			myMoney.setApplyArea(mymoneyAll.getApplyArea());
			myMoney.setCreatUser(user.getName());//创建人
			myMoney.setCreatDept(user.getSaleArea().getSuperior());
			myMoney.setApplyDept(mymoneyAll.getApplyDept());
			//myMoney.setApplyDate(mymoneyAll.getApplyDate());
			myMoney.setApplyDate(mymoneyAll.getApplyDate());
			myMoney.setMemo(mymoneyAll.getMemo());
			myMoneyRepository.save(myMoney);
			myMoneyId = myMoney.getId();
			useContent = myMoney.getUseContent();
			if(mymoneyAll.getLoanMaoney()!=0){
				saveMyMoneyType("借款", mymoneyAll.getLoanMaoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getTravelMoney()!=0){
				saveMyMoneyType("差旅费", mymoneyAll.getTravelMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getHotelMoney()!=0){
				saveMyMoneyType("住宿费", mymoneyAll.getHotelMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getSubsidyMoney()!=0){
				saveMyMoneyType("补贴", mymoneyAll.getSubsidyMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getEntertainmentMoney()!=0){
				saveMyMoneyType("招待费", mymoneyAll.getEntertainmentMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getProjectFeeMoney()!=0){
				saveMyMoneyType("项目费", mymoneyAll.getProjectFeeMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getTelephoneMoney()!=0){
				saveMyMoneyType("电话费", mymoneyAll.getTelephoneMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getTaxiFareMoney()!=0){
				saveMyMoneyType("打的费", mymoneyAll.getTaxiFareMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getSalaryBonusMoney()!=0){
				saveMyMoneyType("工资奖金", mymoneyAll.getSalaryBonusMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getAmountChargeMoney()!=0){
				saveMyMoneyType("冲账金额", mymoneyAll.getAmountChargeMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getBidDocumentMoney()!=0){
				saveMyMoneyType("其他费-购标书", mymoneyAll.getBidDocumentMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getBidServiceMoney()!=0){
				saveMyMoneyType("其他费-中标服务费", mymoneyAll.getBidServiceMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getRetransmissionMoney()!=0){
				saveMyMoneyType("其他费-复传打", mymoneyAll.getRetransmissionMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getPostageMoney()!=0){
				saveMyMoneyType("其他费-邮寄费", mymoneyAll.getPostageMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getSubscriptionMoney()!=0){
				saveMyMoneyType("其他费-入网费", mymoneyAll.getSubscriptionMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getOfficeSuppliesMoney()!=0){
				saveMyMoneyType("其他费-办公用品", mymoneyAll.getOfficeSuppliesMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getWithdrawalProcedureMoney()!=0){
				saveMyMoneyType("其他费-取款手续", mymoneyAll.getWithdrawalProcedureMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getMaintenanceCostMoney()!=0){
				saveMyMoneyType("其他费-维修费", mymoneyAll.getMaintenanceCostMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getHolidayMoney()!=0){
				saveMyMoneyType("其他费-节日费", mymoneyAll.getHolidayMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getOtherChargesMoney()!=0){
				saveMyMoneyType("其他费-其它费", mymoneyAll.getOtherChargesMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getInsuranceMoney()!=0){
				saveMyMoneyType("小车保险费", mymoneyAll.getInsuranceMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getLuqiaoMoney()!=0){
				saveMyMoneyType("小车路桥费", mymoneyAll.getLuqiaoMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getOilMoney()!=0){
				saveMyMoneyType("小车油费", mymoneyAll.getOilMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getRoadToll()!=0){
				saveMyMoneyType("小车过路费", mymoneyAll.getRoadToll(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getParkingMoney()!=0){
				saveMyMoneyType("小车停车费", mymoneyAll.getParkingMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getMaintenanceMoney()!=0){
				saveMyMoneyType("小车保养费", mymoneyAll.getMaintenanceMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getPurchasesMoney()!=0){
				saveMyMoneyType("小车购置物品费", mymoneyAll.getPurchasesMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getLimitedMoney()!=0){
				saveMyMoneyType("小车年审", mymoneyAll.getLimitedMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getRentMoney()!=0){
				saveMyMoneyType("办事处-房租费", mymoneyAll.getRentMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getWaterMoney()!=0){
				saveMyMoneyType("办事处-水电气取暖费", mymoneyAll.getWaterMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getWuguanMoney()!=0){
				saveMyMoneyType("办事处-物管费", mymoneyAll.getWuguanMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getBanTelephoneMoney()!=0){
				saveMyMoneyType("办事处-电话费", mymoneyAll.getBanTelephoneMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getShoppingMoney()!=0){
				saveMyMoneyType("办事处-购置物品费", mymoneyAll.getShoppingMoney(), useContent, myMoneyId, user);
			}
			if(mymoneyAll.getOtherMoney()!=0){
				saveMyMoneyType("办事处-其它费", mymoneyAll.getOtherMoney(), useContent, myMoneyId, user);
			}
			code = 1;
		}else{
			code = 0;
		}
		return code;
	}

	@Override
	public MyMoneyRepository getMyMoneyRepository() {
		return myMoneyRepository;
	}
	
	public void saveMyMoneyType(String kind, Double money, String useContent, String myMoneyId, User user) {
		MyMoneyType myMoneyType = new MyMoneyType();
		myMoneyType.setKind(kind);
		myMoneyType.setMoney(money);
		myMoneyType.setUseContent(useContent);
		myMoneyType.setMyMoneyId(myMoneyId);
		myMoneyType.setApplyUser(user.getName());
		myMoneyTypeRepository.save(myMoneyType);
	}

}
